<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'addUser.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<LINK href="<%=basePath%>/css/main.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
		function findClass(){
			$.post("UserManage?action=findclass",findClassCallBack);
		}
		function findClassCallBack(data){
			var arr=eval(data);			
			var stuclass="<select name='stuClassId'>";
			var str="";
			for(var i =0;i<arr.length;i++){
				str += "<option value='"+arr[i].stuClassId+"'>"+arr[i].className+"</option>";
			}
			var endstr="</select>";
			stuclass = stuclass+str+endstr;	
			iniTable(stuclass);		
		}

		

	 	function check(){
	 		var unlist = document.getElementsByName("userName");
	 		var upwlist = document.getElementsByName("userPassword");
	 		for(var i=0;i<unlist.length;i++){
	 			if(unlist[i].value==""){
	 				alert("第"+(i+1)+"行的用户名不能为空");
	 				return false;
	 			}
	 			if(upwlist[i].value==""){
	 				alert("第"+(i+1)+"行的密码不能为空");
	 				return false;
	 			}
	 		}
	 		return true;
	 	}
	 
	 </script>

</head>

<body onload="findClass()">
<table border="0" width="90%" cellspacing="0" cellpadding="3"
	class="small">
	<tr>
		<td class="Big"><img src="<%=basePath%>/img/menu/comm.gif"
			align="absmiddle"> <span class="big3"> 添加用户</span> <br>
		</td>
	</tr>
</table>
<form method="post" action="UserManage?action=addUser" name="form1"
	onsubmit="return check()">

<div id="div"></div>

<input type="button" value="增加一条数据" onclick="add()" class='BigButton'
	style="margin-left: 350px;" /> <input type="submit" value="提交"
	class='BigButton'> <input type="reset" value="重置"
	class='BigButton'> <input type="button" value="返回"
	class='BigButton' onclick="javascript:history.go(-1)"> <script
	type="text/javascript">

	var row=4;
	var col=2;
	var ss="";
	var div1 = document.getElementById("div");
	var oTable = document.createElement("table");
	oTable.border="1";
	oTable.id="tableID";
	oTable.align="center";
	oTable.width="600";
	oTable.className="TableBlock";


function iniTable(s){
		
	var r0 =oTable.insertRow(0);
	r0.className="Big";
	r0.insertCell(0).appendChild(document.createTextNode("用户名:"));	
	r0.insertCell(1).appendChild(document.createTextNode("密 码:"));	
	r0.insertCell(2).appendChild(document.createTextNode("班 级:"));	
	r0.insertCell(3).appendChild(document.createTextNode("操 作 "));	

	var r1 =oTable.insertRow(1);
	r1.insertCell(0).innerHTML="<input type='text'  name='userName'/>";
	r1.insertCell(1).innerHTML="<input type='text' value='123456'  name='userPassword' onmouseover='this.select()'/>";
	r1.insertCell(2).innerHTML=s;

	div1.appendChild(oTable);
	ss=s;
}
function del(o){
	o.parentNode.parentNode.parentNode.removeChild(o.parentNode.parentNode);
	col--;
}


function add(){
	var tab = document.getElementById("tableID");
	var rows = tab.insertRow(col);

	tab.rows[col].insertCell(0).innerHTML="<input type='text'  name='userName'/>";
	tab.rows[col].insertCell(1).innerHTML="<input type='text'  name='userPassword' value='123456' onmouseover='this.select()' />";
	tab.rows[col].insertCell(2).innerHTML=ss;
	tab.rows[col].insertCell(3).innerHTML="<input type='button' value='删除' onclick='del(this)'/> ";
	col++;
	
}
</script></form>
</body>
</html>
